package org.example.zuoye4;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class main {
    public static void main(String[] args) {
        //两个集合{"a","b","c","d","e"},{"d","e","f","g","h"}合并成一个集合,并且去掉重复的
        List<String> list1 = new ArrayList<>();
        list1.add("a");
        list1.add("b");
        list1.add("c");
        list1.add("d");
        list1.add("e");

        List<String> list2 = new ArrayList<>();
        list2.add("d");
        list2.add("e");
        list2.add("f");
        list2.add("g");
        list2.add("h");

        Set<String> resultSet = new HashSet<>(list1);
        resultSet.addAll(list2);

        List<String> mergedList = new ArrayList<>(resultSet);
        System.out.println("合并并去重后的集合：" + mergedList);
    }
}
